#include "StdAfx.h"
#include "Node.h"
#include "Bounding.h"
#include "ScalableUnitAssist.h"

CBounding::CBounding(void)
{
}

CBounding::~CBounding(void)
{
}

CRectBounding::CRectBounding( CNode* p_pNode, const CPoint& p_delta /*= CPoint(0,0)*/ )
:m_pNode(p_pNode), m_delta(p_delta)
{

}

bool CRectBounding::inRange( const CRect& p_rect )
{
	return m_pNode->getLeftTopPoint().x - m_delta.x >= p_rect.left &&
		   m_pNode->getLeftTopPoint().y - m_delta.y >= p_rect.top  &&
		   m_pNode->getRightBottomPoint().x + m_delta.x <= p_rect.right &&
		   m_pNode->getRightBottomPoint().y + m_delta.y <= p_rect.bottom;
}

bool CRectBounding::pointIn( const CPoint& p_point )
{
	return p_point.x >= m_pNode->getLeftTopPoint().x - m_delta.x &&
		   p_point.y >= m_pNode->getLeftTopPoint().y - m_delta.y &&
		   p_point.x <= m_pNode->getRightBottomPoint().x + m_delta.x &&
		   p_point.y <= m_pNode->getRightBottomPoint().y + m_delta.y;
}
//////////////////////////////////////////////////////////////////////////
CRect CRectBounding::getBoundingRect()
{
	return CRect( CPoint(m_pNode->getLeftTopPoint().x - m_delta.x, m_pNode->getLeftTopPoint().y - m_delta.y),
		CPoint(m_pNode->getRightBottomPoint().x + m_delta.x,  m_pNode->getRightBottomPoint().y + m_delta.y));
}
//////////////////////////////////////////////////////////////////////////

void CBlankRectBounding::setNewBoundRect( const CRect &p_rect )
{
	m_rect = p_rect;
}
//////////////////////////////////////////////////////////////////////////
Anchor_Pos CBlankRectBounding::AnchorSelected(const CPoint& point)
{
	return CScalableUnitAssist::AnchorSelected(m_rect, point);

}

//////////////////////////////////////////////////////////////////////////
Anchor_Pos CRectBounding::AnchorSelected(const CPoint& point)
{
	return CScalableUnitAssist::AnchorSelected(CRect(m_pNode->m_leftTop, m_pNode->m_rightBottom), point);

}
//////////////////////////////////////////////////////////////////////////